package com.u.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.u.Repiar.RepairItem_info;
import com.u.tool.MysqlUtil;

import net.sf.json.JSONArray;

/**
 * Servlet implementation class GetRepairItem
 */
@WebServlet("/GetRepairItem")
public class GetRepairItem extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetRepairItem() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		List<RepairItem_info> list = new ArrayList<>();
		MysqlUtil db = new MysqlUtil();
		db.connection();
		String sql = "SELECT * FROM y_r.repair_item";
		list = db.query(RepairItem_info.class, sql);
		JSONArray json = new JSONArray();
		json.add(list);
		PrintWriter out = response.getWriter();
		out.println(json.toString());
		out.close();
	}

}
